"""Definition of the Personal content type
"""

from AccessControl import ClassSecurityInfo

from zope.interface import implements, directlyProvides

#from Acquisition import aq_parent
#from Products.CMFCore.utils import getToolByName
from Products.Archetypes import atapi
from Products.Archetypes import utils
from Products.ATContentTypes.content import base
from Products.ATContentTypes.content import schemata

from guegue.alcaldias import alcaldiasMessageFactory as _
from guegue.alcaldias.interfaces import IPersonal
from guegue.alcaldias.config import PROJECTNAME

PersonalSchema = schemata.ATContentTypeSchema.copy() + atapi.Schema((

    # -*- Your Archetypes field definitions here ... -*-
    atapi.StringField('title',
                searchable=1,
                isMetadata=0,
                accessor='Title',
                widget=atapi.StringWidget(label='Nombre',
                                      maxlength=150,
                                      size=30,
                                      label_msgid="label_entry_title",
                                      description_msgid="help_entry_title",
                                      i18n_domain="guegue.alcaldias",
                                      description='')),
    atapi.StringField('description',
                searchable=1,
                isMetadata=0,
                accessor='Description',
                widget=atapi.TextAreaWidget(label='Cargo',
                                      label_msgid="label_entry_description",
                                      description_msgid="help_entry_description",
                                      i18n_domain="guegue.alcaldias",
                                      description='')),
    atapi.StringField('dependencia',
                searchable=1,
                isMetadata=0,
		vocabulary="getDependencias",
                widget=atapi.SelectionWidget(label='Dependencia',
                                      label_msgid="label_entry_dependencia",
                                      description_msgid="help_entry_dependencia",
                                      i18n_domain="guegue.alcaldias",
                                      description='')),
    atapi.StringField('correo',
                searchable=0,
                isMetadata=0,
                widget=atapi.StringWidget(label='Correo',
                                      label_msgid="label_entry_correo",
                                      description_msgid="help_entry_correo",
                                      i18n_domain="guegue.alcaldias",
                                      description='')),
    atapi.StringField('telefono',
                searchable=0,
                isMetadata=0,
                widget=atapi.StringWidget(label='Teléfono',
                                      label_msgid="label_entry_telefono",
                                      description_msgid="help_entry_telefono",
                                      i18n_domain="guegue.alcaldias",
                                      description='')),
    atapi.DateTimeField('fecha',
                searchable=0,
                required=0,
                widget=atapi.CalendarWidget(label='Fecha de Ingreso',
                                      label_msgid="label_entry_fecha",
                                      show_hm = False,
                                      description_msgid="help_entry_fecha",
                                      i18n_domain="guegue.alcaldias",
                                      description='')),
    atapi.FixedPointField('salario',
              searchable=0,
              required=0,
              widget=atapi.DecimalWidget(label='Salario (C$)',
                                      label_msgid="label_entry_salario",
                                      description_msgid="help_entry_salario",
                                      i18n_domain="guegue.alcaldias",
                                      description='')),
))

# Set storage on fields copied from ATContentTypeSchema, making sure
# they work well with the python bridge properties.

schemata.finalizeATCTSchema(PersonalSchema, moveDiscussion=False)

class Personal(base.ATCTContent):
    """Tipo de datos para personal"""
    implements(IPersonal)

    def getDependencias(self):
        dl = utils.DisplayList()
        linklist = self.portal_catalog.searchResults(portal_type='Dependencia')
        for link in linklist:
            dl.add(link['id'], link['Title'])
        return dl

    portal_type = "Personal"
    schema = PersonalSchema

    #title = atapi.ATFieldProperty('title')
    #description = atapi.ATFieldProperty('description')

atapi.registerType(Personal, PROJECTNAME)
